<?php

namespace App\Providers;

use Response;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\ServiceProvider;

class ResponseMacroServiceProvider extends ServiceProvider {

    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot() {
        Response::macro('redata', function ($code = '200', $msg = 'success', $data = []) {
            $redata = [
                'code' => $code,
                'msg' => $msg,
                'data' => $data
            ];
            if (empty($data))
                unset($redata['data']);
            return new JsonResponse($redata, 200);
        });
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register() {
        //
    }

}
